<?php

class modLogin extends cDycmsClientModule
{
	function __construct()
	{
		global $gClient;
		
		$form = new cUiForm(array(
			'id'=>'login',
			'action'=>'',
			'method'=>'POST'
		));
		
		
		if($gClient->IsValidated()){
			parent::__construct(uiGetIcon('user').$gClient->GetUserName(),
				array('id' => 'modLogin'));
			
			//
			// Display welcome message and logout button
			//
			
			$this->AddChild('Welcome, '.$gClient->GetUserName());
			$form->AddChild(new cUiFormData('$$ss-loginAction','logout'));
			$form->AddChild(new cUiButton(array(
				'type'=>'submit',
				'id'=>'modLogin-logout',
				'class'=>'triplet'
			), 'Logout', 'door_out'));
		}else{
			parent::__construct(uiGetIcon('key').'Login',
				array('id' => 'modLogin'));
				
			if($_POST['$$ss-loginAction'] == 'login'){
				// Login failed
				$this->AddChild(uiGetIcon('error')
					.'Login failed, check credentials and try again.');
			};
			
			
			//
			// Create login form
			//
			
			$form->AddChild(new cUiFormData('$$ss-loginAction','login'));
			$form->AddChild(new cUiTextBox(array(
				'name'=>'$$ss-uid',
				'id'=>'modLogin-uid'
			), 'User ID'));
			$form->AddChild(new cUiTextBox(array(
				'name'=>'$$ss-pwd',
				'id'=>'modLogin-pwd'
			), 'Password', true));
			$form->AddChild(new cUiButton(array(
				'type'=>'submit',
				'id'=>'modLogin-login',
				'class'=>'triplet'
			), 'Login', 'lock_go'));
		} // if
	$this->AddChild($form);
	}
}

class modClientPassword extends cDycmsClientModule
{
	function __construct() {
		parent::__construct('Change Password');
		$this->AddChild($f = new cUiForm(array(
				'method' => 'POST',
				'action' => ''
		)));
		
		$f->AddChild(new cUiTextBox(array(
				'name' => 'oldPwd',
		),'Old Password', true));
		$f->AddChild(new cUiTextBox(array(
				'name' => 'newPwd',
		),'New Password', true));
		$f->AddChild(new cUiTextBox(array(
				'name' => 'confirmPwd',
		),'Confirm Password', true));
		
		//
		// Buttons
		//
		
		$f->AddChild($btnset = new cDycmsClientNode());
		
		$btnset->AddChild(new cUiButton(array(
				'name' => 'modClientPassword-action',
				'value' => 'cancel',
				'onClick' => 'javascript: history.go(-1); return true;'
		), 'Change Password', 'lock_edit'));
		$btnset->AddChild(new cUiButton(array(
				'name' => 'modClientPassword-action',
				'value' => 'cancel',
				'onClick' => 'javascript: history.go(-1); return true;'
		), 'Cancel', 'cancel'));
	}
}

class modClientReg extends cDycmsClientModule
{
	function __construct() {
		$action = isset($_POST['$modClientReg-action'])
			? $_POST['$modClientReg-action'] : $_GET['$modClientReg-action'];
		$captcha = new cUiCaptcha('modClientReg');
		
		switch($action){
			case 'reg':
			
			
			break;
			
			
			default:
			
			parent::__construct(uiGetIcon('user_add').'Registration');
			
			$captcha->CreateCode();
			
			$this->AddChild($f = new cUiForm());
			
			$f->AddChild(new cUiTextBox(array(
				'name' => '$modUserMgr-uid',
				'value'=>'',
				'title'=>'This is the name you will use to login.'
				), 'User (unique) ID'));
			$f->AddChild(new cUiTextBox(array(
				'name' => '$modUserMgr-name',
				'value'=>'',
				'title'=>'Enter your name as you want others to see it.'
				), 'Display Name'));
			$f->AddChild(new cUiTextBox(array(
				'name' => '$modUserMgr-pwd',
				'value'=> ''
				), 'Password', true));
			$f->AddChild(new cUiTextBox(array(
				'name' => '$modUserMgr-pwdC',
				'value'=> ''
				), 'Confirm Password', true));
			$f->AddChild($captcha);
		};
	}
}
